package com.xiaozhi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.xiaozhi.entity.Student;
import com.xiaozhi.mapper.StudentMapper;
import com.xiaozhi.service.StudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 烟尘
 * @since 2023-03-15
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    @Resource
    private StudentMapper studentMapper;

    @Override
    public List<Student> selectByAny(HashMap<String, Object> map) {
        QueryWrapper<Student> wrapper = new QueryWrapper<>();
        wrapper.allEq(map);
        return studentMapper.selectList(wrapper);
    }

    @Override
    public boolean addStudent(Student student) {
        int insert = studentMapper.insert(student);
        return insert > 0;
    }

    @Override
    public boolean update(Student student) {
        UpdateWrapper<Student> wrapper = new UpdateWrapper<>();
        HashMap<String, Object> map = new HashMap<>();
        map.put("account",student.getAccount());
        wrapper.allEq(map);
        int update = studentMapper.update(student, wrapper);
        return update > 0;
    }
}
